require("../../../wxParse/wxParse.js");

var a = require("../../../utils/api.js"), t = getApp();

Page({
    data: {
        offline: 2,
        show_shop: !0,
        name: "",
        phone: "",
        comment: "",
        id: "",
        diy_community_name: t.globalData.diy_community_name
    },
    onLoad: function(o) {
        console.log(o);
        var e = this, n = o.id;
        e.setData({
            id: n
        }), wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        }), a.getFraction_shopping_info({
            id: n,
            openid: t.globalData.openid
        }).then(function(a) {
            console.log(a), 0 == a.data.status && e.setData({
                info: a.data.data,
                name: a.data.data.member.m_name,
                phone: a.data.data.member.m_phone
            });
        });
    },
    getOffline: function(a) {
        var t = a.currentTarget.dataset.index;
        this.setData({
            offline: t
        });
    },
    showShop: function(a) {
        wx.navigateTo({
            url: "/pages/group/groupList?type=10"
        });
    },
    pickShop: function(a) {
        this.setData({
            show_shop: !this.data.show_shop,
            offline: 2
        });
    },
    keyName: function(a) {
        this.setData({
            name: a.detail.value
        });
    },
    keyMobile: function(a) {
        this.setData({
            phone: a.detail.value
        });
    },
    bindkeyinput: function(a) {
        this.setData({
            comment: a.detail.value
        });
    },
    orderSubmit: function(o) {
        var e = this, n = e.data.info.info.g_id, i = t.globalData.openid, s = e.data.info.commander.m_openid, d = e.data.comment, c = e.data.name, l = e.data.phone;
        if (e.data.disabled) return wx.showToast({
            title: "请10s后再点击哦",
            icon: "none",
            image: "",
            duration: 2e3,
            mask: !0,
            success: function(a) {},
            fail: function(a) {},
            complete: function(a) {}
        }), !1;
        if (e.setData({
            disabled: !0
        }), setTimeout(function() {
            e.setData({
                disabled: !1
            });
        }, 1e4), "" == c || void 0 == c) return wx.showModal({
            title: "提示",
            content: "请输入收货人姓名",
            success: function(a) {
                a.confirm ? console.log("用户点击确定") : a.cancel && console.log("用户点击取消");
            }
        }), !1;
        if ("" == l || void 0 == l) return wx.showModal({
            title: "提示",
            content: "请输入收货人电话",
            success: function(a) {
                a.confirm ? console.log("用户点击确定") : a.cancel && console.log("用户点击取消");
            }
        }), !1;
        wx.showLoading({
            title: "加载中"
        });
        var r = {};
        r.id = n, r.num = 1, r.openid = i, r.oss_openid = s, r.comment = d, r.name = c, 
        r.phone = l, r.formid = o.detail.formId, a.getFraction_shopping(r).then(function(o) {
            1 == o.data.status ? (wx.showModal({
                title: "提示",
                content: o.data.msg,
                showCancel: !1,
                success: function(a) {
                    a.confirm ? console.log("用户点击确定") : a.cancel && console.log("用户点击取消");
                }
            }), wx.hideLoading()) : (wx.hideLoading(), wx.showLoading({
                title: "支付中..."
            }), "" != o.data.data && void 0 != o.data.data ? wx.requestPayment({
                timeStamp: o.data.data.timeStamp,
                nonceStr: o.data.data.nonceStr,
                package: o.data.data.package,
                signType: "MD5",
                paySign: o.data.data.paySign,
                success: function(e) {
                    wx.hideLoading(), console.log(e), a.getFraction_shopping_order({
                        id: o.data.data.id,
                        openid: t.globalData.openid
                    }).then(function(a) {
                        0 == a.data.status ? (wx.showLoading({
                            title: "兑换成功"
                        }), setTimeout(function() {
                            wx.redirectTo({
                                url: "/pages/integralMall/order/order?status=20"
                            });
                        }, 2e3)) : wx.showModal({
                            title: "提示",
                            content: a.data.msg,
                            showCancel: !1,
                            success: function(a) {
                                a.confirm && console.log("用户点击确定");
                            }
                        });
                    });
                },
                fail: function(a) {
                    wx.showLoading({
                        title: "支付取消"
                    }), setTimeout(function() {
                        wx.redirectTo({
                            url: "/pages/integralMall/order/order?status=10"
                        });
                    }, 2e3);
                }
            }) : (console.log(o), wx.showLoading({
                title: "兑换成功"
            }), setTimeout(function() {
                wx.redirectTo({
                    url: "/pages/integralMall/order/order?status=20"
                });
            }, 2e3), wx.hideLoading()));
        });
    },
    onShow: function(o) {
        var e = this, n = e.data.id;
        "" != n && a.getFraction_shopping_info({
            id: n,
            openid: t.globalData.openid
        }).then(function(a) {
            console.log(a), 0 == a.data.status && e.setData({
                info: a.data.data,
                name: a.data.data.member.m_name,
                phone: a.data.data.member.m_phone
            });
        });
    }
});